import React from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import * as userinfoActionsFrom from '../../actions/userinfo.js'
import * as storeActionsFrom from '../../actions/store.js'

import Header from '../../components/Header'
import Userinfo from '../../components/Userinfo'
import OrderList from './subpage/orderList.jsx'

class User extends React.Component{
    constructor(props) {
        super(props)
    }
    render() {
        return (
            <div>
                <Header title="用户主页" history={this.props.history} backRouter='/'></Header>
                <Userinfo userName={this.props.userinfo.userName} cityName={this.props.userinfo.cityName}></Userinfo>
                <div style={{height: '15px'}}></div>
                <OrderList userName={this.props.userinfo.userName}></OrderList>
            </div>
        )
    }
    componentDidMount() {
        if(!this.props.userinfo.userName) {
            this.props.history.push('/login')
        }
    }
}

function mapStateToProps(state) {
    return {
        userinfo: state.userinfo,
        store: state.store
    }
}

function mapDispatchToProps(dispatch) {
    return {
        userinfoActions: bindActionCreators(userinfoActionsFrom, dispatch),
        storeActions: bindActionCreators(storeActionsFrom, dispatch)
    }
}


export default connect(
    mapStateToProps,
    mapDispatchToProps
)(User)